package com.leinbo.onedoc.utils

import com.aspose.cells.Name
import com.aspose.cells.Workbook
import com.aspose.cells.Worksheet
import java.io.File

/**
 * Created by sundaiyue on 2022/11/23 17:06
 */
object ExcelUtil {

    val File.numberOfSheets: Int
        get() = when (this.extension) {
            "xlsx", "xls" -> {
                Workbook(this.absolutePath).worksheets.count
            }

            else -> {
                0
            }
        }

    val File.namesOfSheets: List<String>
        get() = when (this.extension) {
            "xls", "xlsx" -> {
                Workbook(this.absolutePath).worksheets.map { (it as Worksheet).name }
            }

            else -> {
                emptyList()
            }
        }
}
